package logic.service;

import java.util.ArrayList;

import logic.algorithm.greedy.NearestNeighbor;
import logic.objects.Connection;
import logic.objects.Node;
import logic.objects.Problem;

public class PheromonService {

	public static void updateMaxPheromon(Problem prob) {
		prob.getConnections().updateMaxPheromon();
	}

	public static int getPheromon(Connection con, Problem prob) {
		Double dbl = (con.getPheromon() * 100 / prob.getConnections()
				.getMaxPheromon());
		int result = dbl.intValue();
		if (result < 0)
			result = 0;
		if (result > 100)
			result = 100;
		return result;
	}

	public static Double getNearestNeighborShortedTourValue(Problem problem) {
		Double result = NearestNeighbor.getShortestLoop();
		if (result.equals(Double.MAX_VALUE)) {
			NearestNeighbor.solve(problem);
			result = NearestNeighbor.getShortestLoop();
		}
		return result;
	}

	public static ArrayList<Node> getBestSoFarSolution(Problem problem) {
		if (NearestNeighbor.getSolution() == null) {
			NearestNeighbor.solve(problem);
			return NearestNeighbor.getSolution();
		}
		else
			return problem.getBestTourSoFar();
	}
}
